package ar.edu.itba.pod.legajo45002;

import java.io.Serializable;

import org.jgroups.Address;

import ar.edu.itba.pod.legajo45002.api.Signal;

public class DistributedSignal implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Signal s;
	private Address whoHasIt;
	private Address whoBacksItUp;
	
	public DistributedSignal(Signal s,Address whohasit, Address whobacksit) {
		this.s = s;
		this.whoHasIt = whohasit;
		this.whoBacksItUp = whobacksit;
	}
	
	public Signal getS() {
		return s;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((s == null) ? 0 : s.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		DistributedSignal other = (DistributedSignal) obj;
		if (s == null) {
			if (other.s != null)
				return false;
		} else if (!s.equals(other.s))
			return false;
		return true;
	}

	public Address getWhoBacksItUp() {
		return whoBacksItUp;
	}
	
	public Address getWhoHasIt() {
		return whoHasIt;
	}
	
	public void setWhoBacksItUp(Address whoBacksItUp) {
		this.whoBacksItUp = whoBacksItUp;
	}
	public void setWhoHasIt(Address whoHasIt) {
		this.whoHasIt = whoHasIt;
	}
	
	@Override
	public String toString() {
		return "has: "+ this.whoHasIt + " backs: " + whoBacksItUp + " ----";
	}

}
